/**
 * @author: @AngularClass
 */
var path = require('path');

//npm当前执行的环境
const EVENT = process.env.npm_lifecycle_event || '';

// Helper functions
var ROOT = path.resolve(__dirname, '..');
console.log(ROOT);

//检查当前node运行环境
function hasProcessFlag(flag) {
  return process.argv.join('').indexOf(flag) > -1;
}

//检查npm语句
function hasNpmFlag(flag) {
  return EVENT.includes(flag);
}

//判断是否有isDevServer
function isWebpackDevServer() {
  return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1]));
}

//获取根目录的方法
var root = path.join.bind(path, ROOT);

exports.hasProcessFlag = hasProcessFlag;
exports.hasNpmFlag = hasNpmFlag;
exports.isWebpackDevServer = isWebpackDevServer;
exports.root = root;
